package com.settlement.system.service.impl;

import com.settlement.system.model.entity.SysAuditNoLink;
import com.settlement.system.mapper.SysAuditNoLinkMapper;
import com.settlement.system.service.SysAuditNoLinkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.model.query.SysAuditNoLinkQuery;
import com.settlement.system.model.form.SysAuditNoLinkForm;
import cn.hutool.core.bean.BeanUtil;
import com.settlement.system.model.vo.SysAuditNoLinkImportVo;

/**
 * <p>
 * 核销表订单账单对应关系 服务实现类
 * </p>
 *
 * @author huangrensen
 * @since 2024-05-08
 */
@Service
public class SysAuditNoLinkServiceImpl extends ServiceImpl<SysAuditNoLinkMapper, SysAuditNoLink> implements SysAuditNoLinkService {

    @Override
    public Page<SysAuditNoLink> getPage(SysAuditNoLinkQuery queryParams) {
        // 查询参数
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        // 查询数据
        Page<SysAuditNoLink> page = new Page<>(pageNum, pageSize);
        return this.baseMapper.getPage(page, queryParams);
    }

     @Override
     public boolean saveSysAuditNoLink(SysAuditNoLinkForm sysAuditNoLinkForm) {
         SysAuditNoLink sysAuditNoLink = new SysAuditNoLink();
         BeanUtil.copyProperties(sysAuditNoLinkForm, sysAuditNoLink);
         return this.saveOrUpdate(sysAuditNoLink);
     }

     @Override
     public SysAuditNoLinkForm getSysAuditNoLinkFormData(Long id) {
         SysAuditNoLink sysAuditNoLink = this.getById(id);
         SysAuditNoLinkForm sysAuditNoLinkForm = new SysAuditNoLinkForm();
         BeanUtil.copyProperties(sysAuditNoLink, sysAuditNoLinkForm);
         return sysAuditNoLinkForm;
     }

     @Override
     public boolean deleteSysAuditNoLink(String ids) {
        Assert.isTrue(StrUtil.isNotBlank(ids), "删除的数据为空");
        List<Long> idArray = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
        return this.removeByIds(idArray);
     }

    @Override
    public void importData(List<SysAuditNoLinkImportVo> voList)  {
        List<SysAuditNoLink> sysAuditNoLinkList = new ArrayList<>();
        for (SysAuditNoLinkImportVo importVo : voList) {
            SysAuditNoLink sysAuditNoLink = new SysAuditNoLink();
            BeanUtil.copyProperties(importVo, sysAuditNoLink);
            sysAuditNoLinkList.add(sysAuditNoLink);
        }
        this.saveOrUpdateBatch(sysAuditNoLinkList);
    }

    @Override
    public List<SysAuditNoLinkImportVo> findByIds(String idsStr) {
        if (StrUtil.isBlank(idsStr)) {
            return new ArrayList<>();
        }
        List<Long> ids = Arrays.stream(idsStr.split(",")).map(Long::parseLong).collect(Collectors.toList());
        List<SysAuditNoLink> sysAuditNoLinkList = this.getBaseMapper().selectBatchIds(ids);
        List<SysAuditNoLinkImportVo> voList = new ArrayList<>();
        for (SysAuditNoLink sysAuditNoLink : sysAuditNoLinkList) {
            SysAuditNoLinkImportVo vo = new SysAuditNoLinkImportVo();
            BeanUtil.copyProperties(sysAuditNoLink, vo);
            voList.add(vo);
        }
        return voList;
    }
}
